home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / GoodBye / JohnKennedy / February96.lha / MASTERCLASS / MASTERJUNE.LHA / masterjune.doc next >
Encoding:
Text File  |  1996-03-29  |  6.5 KB  |  261 lines

  1. Masterclass
  2.  
  3.  
  4. ARexx is the programming language which comes as part of the
  5. Amiga Operating System. It can be used as a stand-alone
  6. development system for writing utilites and small programs,
  7. or it can be used to control other applications.
  8.  
  9. As it comes "out of the box", ARexx can appear quite a
  10. limiting language. Unless you make use of other
  11. applications, you are stuck with a Shell only text-based
  12. program: and this can look very dated and unimpressive.
  13.  
  14. This month therefore, we'll take a look at some extras
  15. goodies which you can add to your system in order to make
  16. your ARexx programs considerably more powerful -- and user
  17. friendly. They won't cost you anything either, as they are
  18. either already present on your system or available for
  19. downloading from Aminet or a BBS, or if you must, you can
  20. order them from a public domain library.
  21.  
  22. The goodies take the form of special "libraries". The
  23. library files themselves live in the LIBS: directory on your
  24. Workbench system. The libraries add commands which ARexx
  25. will recognise and execute, in exactly the same way as the
  26. standard "built in" commands. If ARexx is installed there
  27. already, you'll see two libraries called:
  28.  
  29.     rexxsyslib.library
  30.     rexxsupport.library
  31.     
  32. The first must be present for ARexx to work at all, as
  33. it contains the basic commands. The second is a library of
  34. extra commands. Most of these commands won't be needed, but
  35. you will occassionally need one or two of them, which is why
  36. they are worth mentioning.
  37.  
  38. First of all though, we need to inform ARexx that the extra
  39. library exists and that we would appreciate it if it check
  40. it out when it found any new commands. There are two ways to
  41. go about this process.
  42.  
  43. The first is to use the ARexx command "ADDLIB". ADDLIB works
  44. from within the ARexx script itself. To load the RexxSupport
  45. library, include ADDLIB as in this short program:
  46.  
  47. ---------------
  48.  
  49. /* ADDLIB example */
  50.  
  51. ADDLIB("rexxsupport.library",0,-30,0)
  52.  
  53. delay(10*50) 
  54.  
  55. ----------------
  56.  
  57.  
  58. (rex1.iff, Use a text editor such as Ed, GoldEd or CygusEd
  59. to enter the ARexx scripts.)
  60.  
  61. If you didn't link in the new library (for example, if you
  62. spelt the library name incorrectly, or simply left that line
  63. out), you'll have seen an error such as "Command returned
  64. 10/15: Function not found".
  65.  
  66. If you got it right, the script will use DELAY to go into a
  67. pause for ten seconds, and then finished. See the box out
  68. for more details of the other new Rexx Support commands.
  69.  
  70. The second way to incorporate the library commands is to use
  71. the "rxlib" command directly from the Shell, before you run
  72. the ARexx script. Here is the command you would enter at the
  73. Shell if you wanted to make use of any of the functions
  74. which are present in the rexxsupport libary.
  75.  
  76.     rxlib rexxsupport.library 0 -30 0
  77.  
  78. The numbers which follow the name of the library are for
  79. setting priorities and checking version numbers: there is
  80. nothing to be gained by altering them.
  81.  
  82. Once you enter this line, the new commands become part of
  83. ARexx. So, for example, you could enter the following script
  84. and execute it:
  85.  
  86. ---------------
  87.  
  88. /* Wait for ten seconds */
  89.  
  90. DELAY(10*50)
  91.  
  92. ---------------
  93.  
  94.  
  95. If you find yourself using the new library commands a lot,
  96. it might be worthwhile adding the rxlib line to your
  97. user-startup sequence. If you are in the habit of sharing
  98. scripts, remember though that other users might not have the
  99. libraries pre-loaded in this way.
  100.  
  101.  
  102.  
  103. DIY Graphical User Interface
  104.  
  105. As you'll have seen, one of the drawbacks of the standard
  106. ARexx system is that it is text only. It looks dated and
  107. dull and at times is a pig to use. Who wants to have to
  108. enter numbers and filenames from the Shell?
  109.  
  110. To see how we can expand ARexx to make use of the standard
  111. Amiga Intuition system, you'll need to get hold of an
  112. archive with the catchy name of "RexxArpLib3_0.lzx". I found
  113. it on Disk A of "Aminet set 2" in the "util/rexx" directory.
  114.  
  115. As you might expect, "RexxArpLib" is another support
  116. library, although this one adds commands which can control
  117. Intuition. To use it, you will need to extract the files and
  118. copy the libraries to the LIBS: drawer on your system. Now,
  119. using one of the two techniques for including the library,
  120. you can you write some ARexx programs to impress your
  121. friends and family (although, let's face it, few will
  122. actually be impressed because they won't have a clue what
  123. you are talking about).
  124.  
  125. Here's a small program which uses RexxArpLib to open some
  126. requestors.
  127.  
  128.  
  129. ---------------
  130.  
  131. /* The REAL Rod Hull tester */
  132.  
  133. ADDLIB("rexxarplib.library",0,-30,0)
  134.  
  135.  
  136. answer= request(25,25," Do like Green Jelly? ",,"Yes","No")
  137.  
  138. if answer='OKAY' then
  139.     request(80,40,"Good for you!",,"I LOVE it!")
  140. else
  141.     request(80,40,"You are an imposter!",,"Sorry")
  142.  
  143.  
  144. ---------------
  145.  
  146. (rex2.iff)
  147.  
  148.  
  149. If you look through the copious documentation supplied with
  150. RexxArpLib you'll see that there are dozens of new commands.
  151. These can be used to open Windows, call standard
  152. FileRequestors set up gadgets. Your Arexx Scripts need never
  153. be dull again!
  154.  
  155. (rex3.iff, The RexxArp library includes routines to open
  156. requestors for almost everything -- including Fonts and
  157. files.)
  158.  
  159.  
  160.  
  161.  
  162. Box out: Some of the new funtions in RexxSupport Library
  163.  
  164.  
  165. DELAY(n)
  166.  
  167.     Pause the program for n ticks -- a tick is 1/50th of a
  168. second on PAL Amigas.
  169.  
  170.     Example:        Delay(500)    /* Wait 10 seconds */
  171.  
  172. FORBID(), PERMIT()
  173.  
  174.     These commands suspend and reactivate multitasking. You 
  175. should only really need to use these when you are performing
  176. some kind of low-level memory access and it is imperitive no
  177. other program can interfere.
  178.  
  179.     Example:
  180.  
  181.         /* Forbit/Permit */
  182.  
  183.         ADDLIB("rexxsupport.library",0,-30,0)
  184.  
  185.         DELAY(100)
  186.         FORBID()
  187.         SAY "I have control now."
  188.         DO 50000; END
  189.         SAY "Back to you, master"
  190.         PERMIT()
  191.         DELAY(100)
  192.  
  193.         /* end */
  194.  
  195.  
  196. DELETE(filename)
  197.  
  198.     Erase an AmigaDOS file. Wildcards are not allowed.
  199. Returns 0 if deleting the file is not possible.
  200.  
  201.     example:
  202.     
  203.     /* Delete me ! */
  204.  
  205.     ADDLIB("rexxsupport.library",0,-30,0)
  206.  
  207.     plop=delete("ram:test.dat")
  208.  
  209.     if plop=0 then 
  210.         say "Sorry, couldn't delete that file."
  211.  
  212.     /* end */
  213.  
  214.  
  215.  
  216. MAKEDIR(directory name)
  217.  
  218.     Create an AmigaDOS Directory.
  219.  
  220.     Example:
  221.  
  222.             MAKEDIR("ram:plop")
  223.  
  224. RENAME (oldname, newname)
  225.  
  226.     Rename a file or directory
  227.  
  228.     Example:
  229.             RENAME ("old.dat","old.bak")
  230.  
  231.  
  232.  
  233.  
  234.  
  235. Hot tip
  236.  
  237. Sometimes you may need to perform a quick calculation whilst
  238. you are seated at your Amiga, and frankly you couldn't be
  239. bothered trying to find a pocket calculator or even run a
  240. calculator program. Here's how ARexx can be used.
  241.  
  242. All you have to do is pen a Shell, and enter something like:
  243.  
  244. rx "say 173*34"
  245.  
  246. or
  247.  
  248. rx "say 182/11"
  249.  
  250.  
  251. (rex4.iff, Use ARexx from the Shell to save you fumbling for a calculator)
  252.  
  253.  
  254.  
  255. --
  256.  
  257. John Kennedy
  258.  
  259.  
  260.  
  261.